﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net;

using imeem.api;

namespace ImeemUploadr
{
	public partial class uploadr : Form
	{
		private UploadType selectedType = UploadType.photo;
		
		//For Development Purposes, should probably put these into a .config file.
		//OR one could actually validate the user input.
		private string email = string.Empty;
		private string password = string.Empty;
		private string imeemApiKey = string.Empty;
		private string imeemApiSecret = string.Empty;
		private string fileToUpload = string.Empty;
		
		public uploadr()
		{
			InitializeComponent();
			//
			//Read comments above...
			//txtBoxApiKey.Text = imeemApiKey;
			//txtBoxApiSecret.Text = imeemApiSecret;
			//txtBoxEmail.Text = email;
			//txtBoxPassword.Text = password;
			//
			//TODO: This is VERY ghetto shouldn learn how to use DataSet to just pass the right things into the combobox!
			cmbMediaType.Items.Add(UploadType.photo.ToString());
			cmbMediaType.Items.Add(UploadType.music.ToString());
			cmbMediaType.Items.Add(UploadType.video.ToString());
			cmbMediaType.SelectedIndex = 0;
		}
		
		private void bbGetFiles_Click(object sender, EventArgs e)
		{
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				fileToUpload = openFileDialog.FileName;
				textBox1.Text = openFileDialog.FileName;
			}
		}
		
		private void llupload_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			Users users = new Users(this.imeemApiKey, this.imeemApiSecret);
			CookieCollection authCookies = users.LoginUser(this.email, this.password, false);
			MediaUpload mediaUpload = new MediaUpload(this.imeemApiKey, this.imeemApiSecret, authCookies);
			mediaUpload.InvokeUpload(fileToUpload, selectedType);
		}
		
		//TODO: This is VERY ghetto should learn how to use DataSet to just pass the right things into the combobox!
		private void cmbMediaType_SelectedIndexChanged(object sender, EventArgs e)
		{
			string type = cmbMediaType.SelectedItem as string;
			switch(type)
			{
				case "photo":
					{
						this.selectedType = UploadType.photo;
						break;
					}
				case "music":
					{
						this.selectedType = UploadType.music;
						break;
					}
				case "video":
					{
						this.selectedType = UploadType.video;
						break;
					}
			}
		}
	}
}
